package com.smbms.controller;

import com.smbms.pojo.User;
import com.smbms.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {

    @Resource
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/userLogin")
    public Object login(@RequestBody Map<String,Object> paramsMap, HttpSession session){
        User user=userService.getUserByLogin(paramsMap);
        Map<String,Object> result=new HashMap<>();
        if (user!=null){
            //登录成功
            session.setAttribute("LOGIN_USER",user);
            result.put("flag",true);
            result.put("msg","用户登陆成功");
            result.put("data",user);
        }else {
            result.put("flag",false);
            result.put("msg","用户名或密码错误");
        }
        return result;
    }
}
